home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / UUCP / UUX.C < prev    next >
C/C++ Source or Header  |  1993-10-03  |  43KB  |  1,224 lines

  1. /*--------------------------------------------------------------------*/
  2. /*          u u x . c                                                 */
  3. /*                                                                    */
  4. /*          Queue remote commands for UUCP under UUPC/extended        */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*       Changes Copyright (c) 1989-1993 by Kendra Electronic         */
  9. /*       Wonderworks.                                                 */
  10. /*                                                                    */
  11. /*       All rights reserved except those explicitly granted by       */
  12. /*       the UUPC/extended license agreement.                         */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: uux.c 1.8 1993/10/03 20:43:08 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: uux.c $
  24.  * Revision 1.8  1993/10/03  20:43:08  ahd
  25.  * Normalize comments to C++ double slash
  26.  *
  27.  * Revision 1.7  1993/10/01  01:17:44  ahd
  28.  * Additional correct from Richard Gumpertz
  29.  *
  30.  * Revision 1.6  1993/09/28  01:38:19  ahd
  31.  * Corrections from Robert H. Gumpertz (rhg@cps.com)
  32.  *
  33.  * Revision 1.5  1993/09/20  04:48:25  ahd
  34.  * TCP/IP support from Dave Watt
  35.  * 't' protocol support
  36.  * OS/2 2.x support (BC++ 1.0 for OS/2)
  37.  *
  38.  */
  39.  
  40. /*
  41.       Program:    uux.c              27 August 1991
  42.       Author:     Mitch Mitchell
  43.       Email:      mitch@harlie.lonestar.org
  44.  
  45.       Much of this code is shamelessly taken from extant code in
  46.       UUPC/Extended.
  47.  
  48.       Usage:      uux [ options ] command-string
  49.  
  50.                Where [ options ] are:
  51.  
  52.      -aname    Use name as the user identification replacing the initiator
  53.                user-id.  (Notification will be returned to the user.)
  54.  
  55.      -b        Return whatever standard input was provided to the uux command
  56.                if the exit status is non-zero.
  57.  
  58.      -c        Do not copy local file to the spool directory for transfer to
  59.                the remote machine (default).
  60.  
  61.      -C        Force the copy of local files to the spool directory for
  62.                transfer.
  63.  
  64.      -e        Remote system should use sh to execute commands.
  65.  
  66.      -E        Remote system should use exec to execute commands.
  67.  
  68.      -ggrade   Grade is a single letter/number; lower ASCII sequence
  69.                characters will cause the job to be transmitted earlier during
  70.                a particular conversation.
  71.  
  72.      -j        Output the jobid ASCII string on the standard output which is
  73.                the job identification.  This job identification can be used by
  74.                uustat to obtain the status or terminate a job.
  75.  
  76.      -n        Do not notify the user if the command fails.
  77.  
  78.      -p        The standard input to uux is made the standard input to the
  79.                command-string.
  80.  
  81.      -r        Do not start the file transfer, just queue the job.
  82.                (Currently uux does not attempt to start the transfer
  83.                 regardless of the presense of this option).
  84.  
  85.      -sfile    Report status of the transfer in file.
  86.  
  87.      -xdebug_level
  88.                Produce debugging output on the standard output.  The
  89.                debug_level is a number between 0 and ??; higher numbers give
  90.                more detailed information.
  91.  
  92.      -z        Send success notification to the user.
  93.  
  94.  
  95.       The command-string is made up of one or more arguments that
  96.       look like a normal command line, except that the command and
  97.       filenames may be prefixed by system-name!.  A null
  98.       system-name is interpreted as the local system.
  99.  
  100. */
  101.  
  102. /*--------------------------------------------------------------------*/
  103. /*         System include files                                       */
  104. /*--------------------------------------------------------------------*/
  105.  
  106. #include <stdio.h>
  107. #include <io.h>
  108. #include <string.h>
  109. #include <time.h>
  110. #include <stdlib.h>
  111. #include <fcntl.h>
  112. #include <sys/types.h>
  113. #include <sys/stat.h>
  114.  
  115. #ifdef _Windows
  116. #include <windows.h>
  117. #endif
  118.  
  119. /*--------------------------------------------------------------------*/
  120. /*         Local include files                                        */
  121. /*--------------------------------------------------------------------*/
  122.  
  123. #include  "lib.h"
  124. #include  "hlib.h"
  125. #include  "getopt.h"
  126. #include  "getseq.h"
  127. #include  "expath.h"
  128. #include  "import.h"
  129. #include  "pushpop.h"
  130. #include  "security.h"
  131. #include  "hostable.h"
  132. #include  "timestmp.h"
  133.  
  134. #ifdef _Windows
  135. #include "winutil.h"
  136. #include "logger.h"
  137. #endif
  138.  
  139. /*--------------------------------------------------------------------*/
  140. /*        Define current file name for panic() and printerr()         */
  141. /*--------------------------------------------------------------------*/
  142.  
  143. currentfile();
  144.  
  145. /*--------------------------------------------------------------------*/
  146. /*                          Global variables                          */
  147. /*--------------------------------------------------------------------*/
  148.  
  149. typedef enum {
  150.           FLG_USE_USERID,
  151.           FLG_OUTPUT_JOBID,
  152.           FLG_READ_STDIN,
  153.           FLG_QUEUE_ONLY,
  154.           FLG_NOTIFY_SUCCESS,
  155.           FLG_NONOTIFY_FAIL,
  156.           FLG_COPY_SPOOL,
  157.           FLG_RETURN_STDIN,
  158.           FLG_STATUS_FILE,
  159.           FLG_USE_EXEC,
  160.           FLG_MAXIMUM
  161.        } UuxFlags;
  162.  
  163. typedef enum {
  164.       DATA_FILE   = 0,        // Normal data file passed argument
  165.       INPUT_FILE  = 1,        // Redirected stdin file
  166.       OUTPUT_FILE = 2         // Redirected stdout file
  167.       } FileType;
  168.  
  169. static boolean flags[FLG_MAXIMUM] = {
  170.                                         FALSE,
  171.                                         FALSE,
  172.                                         FALSE,
  173.                                         FALSE,
  174.                                         FALSE,
  175.                                         FALSE,
  176.                                         FALSE,
  177.                                         FALSE,
  178.                                         FALSE,
  179.                                         FALSE
  180.                                     };
  181. static char* st_out = NULL;
  182. static char* user_id = NULL;
  183. static char  grade = 'Z';          // Default grade of service
  184.  
  185. static char  job_id[15];
  186.  
  187. static char* spool_fmt = SPOOLFMT;
  188. static char* dataf_fmt = DATAFFMT;
  189.  
  190. static char* send_cmd  = "S %s %s %s - %s 0666\n";
  191.  
  192. /*--------------------------------------------------------------------*/
  193. /*                        Internal prototypes                         */
  194. /*--------------------------------------------------------------------*/
  195.  
  196. void main(int  argc, char  **argv);
  197. static void usage( void );
  198. static char *SwapSlash(char *p);
  199. static boolean cp(char *from, char *to);
  200. static boolean split_path(char *path,
  201.                           char *system,
  202.                           char *file,
  203.                           boolean expand,
  204.                           char *default_sys);
  205. static boolean CopyData( const char *input, const char *output);
  206.  
  207. static boolean do_uuxqt(char *job_name, char *src_syst, char *src_file, char *dest_syst, char *dest_file);
  208.  
  209. static boolean do_copy(char *src_syst, char *src_file, char *dest_syst, char *dest_file);
  210.  
  211. static boolean do_remote(int optind, int argc, char **argv);
  212. static void preamble(FILE* stream);
  213. static char subseq( void );
  214.  
  215. /*--------------------------------------------------------------------*/
  216. /*    u s a g e                                                       */
  217. /*                                                                    */
  218. /*    Report flags used by program                                    */
  219. /*--------------------------------------------------------------------*/
  220.  
  221. static void usage()
  222. {